\chapter{Implementation}
\section{Implementing the Light and Shadow Mechanic}
Since lights and shadows play a big part in \textit{See You On The Other Side}, it was necessary to find a way for the lights to work as intended, i.e.\ letting the player collide with objects only if he is inside a light. Similarly, if he is in shadow, he should not collide with other objects.

\begin{figure}[htbp]
\centering
\includegraphics[width=0.35\textwidth]{Pictures/Design/LightDetector}
\caption{Person A is in light; Person B is in the cone of light but blocked by a box; Person C is not in light.}
\label{fig:lightDetector}
\end{figure}

This was implemented by having each light source calculate an angle between itself and the player, using Unity's built-in \textit{Vector3.Angle} function \citep{unityVectorAngle}. Each light source is a spotlight, meaning it has a spot angle. If the angle between the spotlight and the player is smaller than the light's spot angle, the player must be inside cone of the light. However, it is possible that other objects are occluding the line between the spotlight and the player, which is why it is necessary to also cast a \textit{raycast} \citep{unityRaycast} in order to know whether or not the spotlight is actually hitting the player. If this ray indeed hits the player, he is inside the spotlight and should therefore collide with objects in the game. Figure \ref{fig:lightDetector} illustrates this.

This procedure is repeated for all the lights in the scene. If none hit the player, then he must be in shadow and should therefore not collide with objects. This is done using Unity's Physics Manager \citep{unityPhysicsManager} where it's possible to decide which physics layers should collide with each other. When the player is in shadow, his layer is changed so that he won't collide with any of the objects in the scene.